// pages/dashboard/sensorStatus/sensorStatus.js
var appInstance = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hw:"N/A",
    fw:"N/A",
    battery:"N/A",
    sn:"N/A",
    mac:"N/A"
  },
  disconnect(){
    let deviceId = appInstance.globalData.deviceId
    appInstance.disconnectECG(deviceId);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      hw:options.hw,
      fw:options.fw,
      battery:options.battery,
      sn:options.sn,
      mac:"N/A"
    })

    wx.onBLEConnectionStateChange((result) => {
      console.log(`device ${result.deviceId} state has changed, connected: ${result.connected}`)
      if (!result.connected) {
        appInstance.globalData.ecg = {connected:false,battery:"100",deviceName:""}
        wx.navigateBack({
          delta:1,
        })
        // wx.reLaunch({
        //   url: '../../dashboard/dashboard',
        // })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})